package cn.itcast.p2p20.act;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.widget.RadioGroup;

import java.util.ArrayList;

import cn.itcast.p2p20.R;
import cn.itcast.p2p20.fragments.HomeFragment;
import cn.itcast.p2p20.fragments.InvestFragment;
import cn.itcast.p2p20.fragments.MeFragment;
import cn.itcast.p2p20.fragments.MoreFragment;

public class MainActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {

    private RadioGroup mRadioGroup;
    private FragmentManager mFragmentManager;
    private ArrayList<Fragment> mFragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mFragmentManager = getSupportFragmentManager();
        mFragments = new ArrayList<>();
        mFragments.add(new HomeFragment());
        mFragments.add(new InvestFragment());
        mFragments.add(new MeFragment());
        mFragments.add(new MoreFragment());


        mRadioGroup = ((RadioGroup) findViewById(R.id.radiogroup_home));
        mRadioGroup.setOnCheckedChangeListener(this);
        mRadioGroup.check(R.id.rb_home);

    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {

        int index = group.indexOfChild(group.findViewById(checkedId));
        Fragment fragment = mFragments.get(index);
        mFragmentManager.beginTransaction().replace(R.id.fl_fragment_container, fragment).commit();
    }
}
